package com.sws.hm.controller;


import com.sws.common.BaseResponse;
import com.sws.common.StatusCode;
import com.sws.hm.dao.SysinfoDao;
import com.sws.hm.entity.Cpuinfo;
import com.sws.hm.entity.Meminfo;
import com.sws.hm.entity.Sys;
import com.sws.hm.entity.Sysfileinfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/sys")
@CrossOrigin
@Slf4j
public class SysinfoController {


    @Autowired
    private SysinfoDao dao;

    @RequestMapping("findAll")
    public BaseResponse add(String computerIp) {

        List<Sys> sysInfos = dao.findAll(computerIp);
        BaseResponse response=new BaseResponse(StatusCode.Success);
        response.setMsg("查询所有主机信息成功");
        response.setCount(sysInfos.size());
        response.setData(sysInfos);
        return response;
    }
    @RequestMapping("deleteByIp")
    public BaseResponse deleteByIp(String computerIp) {
        int num=dao.deleteByIp(computerIp);
        BaseResponse response=new BaseResponse(StatusCode.Success);
        response.setMsg("主机删除成功");
        response.setCount(num);
        return response;
    }

    @RequestMapping("computerRemark")
    public BaseResponse computerRemark(@Param("computerIp")String computerIp, @Param("computerRemark")String computerRemark) {
        int num=dao.computerRemark(computerIp,computerRemark);
        BaseResponse response=new BaseResponse(StatusCode.Success);
        response.setMsg("主机备注修改成功");
        response.setCount(num);
        return response;
    }

    @RequestMapping("selectSysinfo")
    public BaseResponse selectSysinfo(@Param("computerIp")String computerIp) {
        List<Sys> sys = dao.selectSysinfo(computerIp);
        BaseResponse response=new BaseResponse(StatusCode.Success);
        response.setMsg("查询主机信息成功");
        response.setCount(sys.size());
        response.setData(sys);
        return response;
    }

    @RequestMapping("selectNewSysinfo")
    public BaseResponse selectNewSysinfo(@Param("computerIp")String computerIp) {
        System.out.println("selectNewSysinfo:"+computerIp);
        Sys sys = dao.selectNewSysinfo(computerIp);
        BaseResponse response=new BaseResponse(StatusCode.Success);
        response.setMsg("查询主机信息成功");
        response.setCount(1);
        response.setData(sys);
        return response;
    }

    @RequestMapping("selectSysfileinfo")
    public BaseResponse selectSysfileinfo(@Param("computerIp")String computerIp) {
        System.out.println("computerIp:"+computerIp);
        List<Sysfileinfo> sysfileinfos = dao.selectSysfileinfo(computerIp);
        BaseResponse response=new BaseResponse(StatusCode.Success);
        response.setMsg("查询硬盘信息成功");
        response.setCount(sysfileinfos.size());
        response.setData(sysfileinfos);
        return response;
    }
    @RequestMapping("selectNewSysfileinfo")
    public BaseResponse selectNewSysfileinfo(@Param("computerIp")String computerIp) {
        System.out.println("computerIp:"+computerIp);
        Sysfileinfo sysfileinfos = dao.selectNewSysfileinfo(computerIp);
        BaseResponse response=new BaseResponse(StatusCode.Success);
        response.setMsg("查询硬盘信息成功");
        response.setCount(1);
        response.setData(sysfileinfos);
        return response;
    }

    @RequestMapping("selectCpuinfo")
    public BaseResponse selectCpuinfo(@Param("computerIp")String computerIp) {
        System.out.println("computerIp:"+computerIp);
        List<Cpuinfo> cpuinfos = dao.selectCpuinfo(computerIp);
        BaseResponse response=new BaseResponse(StatusCode.Success);
        response.setMsg("查询cpu信息成功");
        response.setCount(cpuinfos.size());
        response.setData(cpuinfos);
        return response;
    }
    @RequestMapping("selectNewCpuinfo")
    public BaseResponse selectNewCpuinfo(@Param("computerIp")String computerIp) {
        System.out.println("computerIp:"+computerIp);
        Cpuinfo cpuinfos = dao.selectNewCpuinfo(computerIp);
        BaseResponse response=new BaseResponse(StatusCode.Success);
        response.setMsg("查询cpu信息成功");
        response.setCount(1);
        response.setData(cpuinfos);
        return response;
    }

    @RequestMapping("selectMeminfo")
    public BaseResponse selectMeminfo(@Param("computerIp")String computerIp) {
        System.out.println("computerIp:"+computerIp);
        List<Meminfo> meminfos = dao.selectMeminfo(computerIp);
        BaseResponse response=new BaseResponse(StatusCode.Success);
        response.setMsg("查询内存信息成功");
        response.setCount(meminfos.size());
        response.setData(meminfos);
        return response;
    }
    @RequestMapping("selectNewMeminfo")
    public BaseResponse selectNewMeminfo(@Param("computerIp")String computerIp) {
        System.out.println("computerIp:"+computerIp);
        Meminfo meminfos = dao.selectNewMeminfo(computerIp);
        BaseResponse response=new BaseResponse(StatusCode.Success);
        response.setMsg("查询内存信息成功");
        response.setCount(1);
        response.setData(meminfos);
        return response;
    }
}
